package com.example.edianzu.somur.module.exercise.adapter;

import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.edianzu.somur.R;
import com.example.edianzu.somur.module.exercise.bean.ExerciseInfo;
import com.example.edianzu.somur.module.health.adapter.HealthAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author：风不会停息 on 2017/7/26 17:24
 * mailbox：yh131412hys@163.com
 * project：Somur
 * tel：13295355900
 * describe：
 */

public class ExerciseAdapter extends RecyclerView.Adapter<ExerciseAdapter.ViewHolder> {

    private List<ExerciseInfo.DataBean> dataBeen;
    private HealthAdapter.OnItemClickListener onItemClickListener;

    public ExerciseAdapter(List<ExerciseInfo.DataBean> dataBeen) {
        this.dataBeen = dataBeen;
    }

    public void setOnItemClickListener(HealthAdapter.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    private RecyclerView.AdapterDataObserver observer = new RecyclerView.AdapterDataObserver() {
        @Override
        public void onChanged() {//设置空view原理都一样，没有数据显示空view，有数据隐藏空view
//            RecyclerView.Adapter adapter = getAdapter();
//            if (adapter.getItemCount() == 0) {
//                emptyView.setVisibility(VISIBLE);
//                RecyclerViewForEmpty.this.setVisibility(GONE);
//            } else {
//                emptyView.setVisibility(GONE);
//                RecyclerViewForEmpty.this.setVisibility(VISIBLE);
//            }
        }
    };

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_exercise, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {

        holder.fragmentExerciseContent.setText(dataBeen.get(position).getTitle());
        if (onItemClickListener != null) {

            holder.fragmentExerciseItemLinearLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    onItemClickListener.onItemClickListener(v,holder.getLayoutPosition());
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return dataBeen!=null?dataBeen.size():0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.fragment_exercise_content)
        AppCompatTextView fragmentExerciseContent;
        @BindView(R.id.fragment_exercise_item_LinearLayout)
        LinearLayoutCompat fragmentExerciseItemLinearLayout;

        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
